package com.zking.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.zking.frame.LYK.JDBC;

public class FilmRankingDao {

	public static List<Map<String ,Object>>getFilmRanking (){
		List<Map<String ,Object>> list=new ArrayList<Map<String,Object>>();
		Connection conn=JDBC.getConn();
		String sql ="select  film_name,film_score from film order by film_score desc";
		PreparedStatement pst=null;
		ResultSet rs=null;
			
		try {
			pst=conn.prepareStatement(sql);
			rs =pst.executeQuery();
			while(rs.next()){
				Map<String ,Object> map=new HashMap<String, Object>();
				String filmname=rs.getString("film_name");
				map.put("电影名", filmname);
				double film_score=rs.getDouble("film_score");
				map.put("评分", film_score);
				
				list.add(map);
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			ColseSql.colseAllsql(pst, rs, conn);
		}
		
		
		return list;
	}
	public static void main(String[] args) {
		List<Map<String ,Object>> list=getFilmRanking();
		System.out.println(list.size());
	}
}
